package com.sphd.emanu.activity.addcard;

import android.content.Context;

import com.sphd.emanu.mvp.BasePresenterImpl;

import java.io.IOException;
import java.util.Map;

import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * MVPPlugin
 * 邮箱 784787081@qq.com
 */

public class AddCardPresenter extends BasePresenterImpl<AddCardContract.View> implements AddCardContract.Presenter {

    @Override
    public void addAccount(Map<String, String> map) {
        emanuService.addAccount(map).enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                try {
                    String result = response.body().string();
                    mView.success(result);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                Error(t);
            }
        });

    }

    @Override
    public void changeAccountRequest(Map<String, String> map) {
        emanuService.changeAccountRequest(map).enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                try {
                    String result = response.body().string();
                    mView.success(result);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                Error(t);
            }
        });
    }
}
